package isnork.g2;

import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.Set;

import javax.naming.directory.DirContext;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction;

import isnork.g2.utility.Utility;
import isnork.sim.GameObject;
import isnork.sim.Observation;
import isnork.sim.SeaLifePrototype;
import isnork.sim.GameObject.Direction;
import isnork.g2.iSnorkConfig;
import isnork.g2.iSnorkConfig.Creatures;


public class iSnorkStrategy implements Strategy {
	
	
	@Override	
	public Map<Direction, Double> process(G2Explorer diver) {
		Map<Direction, Double> utility_accumulator = new HashMap<Direction, Double>();
		try {
		Creatures c = diver.config.decodeReceivedMessages(diver);
		if (c == null)
			return null;
		Direction dir = Utility.RelativeDirection(diver.location, c.loc);
		double dist = c.loc.distance(diver.location);
		if (dist < diver.r / 2)
			return null;
		double utility = 0.0;
		if (c.creature.getSpeed() == 0)
			utility = c.value * ExplorerConfig.isnork_c;
		else
			utility = c.value / dist * ExplorerConfig.isnork_c;
		//Utility.AdjacentDirections(dir)
		utility_accumulator.put(dir, utility);
		} catch (Exception e)
		{
			e.printStackTrace();
			System.out.printf(e.getMessage());
		}
		System.out.println("Diver: "+diver.getName()+" : insork utility:"+utility_accumulator);
		return utility_accumulator;
	}
}